import java.util.Scanner;
public class C_2019_lanqiao_2304 {
    public static void main(String[] args) {
        int a,num = 0;Scanner sc = new Scanner(System.in);a = sc.nextInt();
        for (int i = 1; i <= a; i++) { char[] c;c = (i + "").toCharArray();for (char t : c) { if (t == '2' || t == '0' || t == '1' || t == '9') { num += i;break; } } }
        System.out.println(num); }}
